package jianzhi_offer;

import java.util.Arrays;

public class _36_数字在排序数组中出现的次数 {
    public int GetNumberOfK(int [] array , int k) {
        int index = Arrays.binarySearch(array,k);
        if(index < 0) return 0;//没有此元素
        int left = index,right = index;
        while(left >=0 && array[left] == k) --left;
        while(right < array.length && array[right] == k) ++right;
        return right-left-1;
    }
}
